package com.mytest.leetcode;

import lombok.extern.slf4j.Slf4j;

/**
 * Created by shixi  on 2020/1/17
 */
@Slf4j
public class Solution566 {

    public static void main(String[] args) {
        Solution566 solution121 = new Solution566();
        int [] nums = {2,4,7,3,5,9};
        int [] nums1 = new int[]{7,1,5,3,6,4};
        int [ ][ ] arr={{22,15,32,20,18},{12,21,25,19,33},{14,58,34,24,66},{7,1,5,3,6}};
        int[][] merger ={nums,nums1};
        int[][] result = solution121.matrixReshape(arr, 2,10);

        log.info("{}",result);
    }

    public int[][] matrixReshape(int[][] mat, int r, int c) {
        int r1 = mat.length;
        int c1 = mat[0].length;

        if(r1*c1 != r*c) {
            return mat;
        }
        int [][] result = new int[r][c];
        for(int i=0;i< r*c;i++) {
            result[i/c][i%c] = mat[i/c1][i%c1];
        }
        return result;
    }
}
